<!--
 * @title: 用户维护
 * @author: andy.ten@tom.com & xukaixing@hotmail.com
 * @Date: 2022-03-30 14:58:25
 * @LastEditors: andy.ten@tom.com
 * @LastEditTime: 2022-04-27 08:09:02
 * @version: 1.0.3
 * @copyright: copyright (c) 2022 andyten
 *  node: you can not copy and/or use and/or modify this program free,
 *  please reserve the segment above.Please mail me if you have any question.
-->
<template>
  <div>
    <!-- 查询条件表单 -->
    <ht-form ref="userSearchFm" ref-form="userSearchFm" divider="检索分栏" :form-list="userSearchList">
      <ht-search-bar>
        <ht-button @click="handleSearch()">检索</ht-button>
        <ht-button>重置</ht-button>
      </ht-search-bar>
    </ht-form>
    <ht-table ref="userTableList" ref-table="userTableList" :table-head="tableHeadList" :table-data="searchUserData" :page-size="10" :table-export="true">
      <ht-button @click="dialogVisible = !dialogVisible">新增</ht-button>
      <ht-button>导入模版下载</ht-button>
      <ht-button>导入表格</ht-button>
    </ht-table>
    <!-- <el-button icon="ht-icon-chuangkou01" @click="dialogVisible=true">抽屉浮动框</el-button> -->
    <user-edit v-if="dialogVisible" :visible.sync="dialogVisible" />
  </div>

</template>
<script>
import UserEdit from './module/userEdit';
import { findUsers } from '@/api/ht.admin';
export default {
  name: 'UserIndex',
  components: { UserEdit },
  data() {
    return {
      dialogVisible: false,
      count: 0,
      userSearchList: [
        {
          type: 'text',
          format: [0, 'is_any', 3],
          label: '用户账号',
          field: 'account'
        },
        {
          type: 'text',
          format: [0, 'is_any', 30],
          label: '用户姓名',
          field: 'userName'
        },
        {
          type: 'dic',
          format: [0, 'isDic', 30],
          dicType: 'yxzt',
          label: '状态',
          field: 'status'
        },
        {
          type: 'text',
          format: [0, 'isAny', 30],
          label: '岗位',
          field: 'postStation'
        }

      ],
      tableHeadList: [
        {
          type: 'action',
          label: '操作',
          content: ['编辑', '删除'],
          action: [
            (row, index) => this.handleEdit(row, index),
            (row, index) => this.handleDel(row, index)
          ]
        },
        {
          label: '用户账号',
          prop: 'account',
          fixed: 'left',
          align: 'right',
          query: true
        },
        {
          label: '用户姓名',
          prop: 'userName',
          fixed: 'left',
          query: true
        },
        {
          label: '工号',
          prop: 'userSn'
        },
        {
          label: '岗位',
          prop: 'postStation'
        },
        {
          label: '出生日期',
          prop: 'birthDate'
        },
        {
          label: '性别',
          prop: 'sex',
          type: 'dic',
          dicType: 'xb'
        },
        {
          label: '手机号码',
          prop: 'mobile',
          align: 'right'
        },
        {
          label: '邮箱地址',
          prop: 'email'
        },
        {
          label: '用户类型',
          prop: 'userType'
        },
        {
          label: '用户级别',
          prop: 'userLevel'
        },
        {
          label: '状态',
          prop: 'status',
          render: (scope) => {
            return (
              <ht-switch
                value={scope.row.status.c}
                key={scope.column.columnKey}
                onChange={(newValue) => this.testRefer(newValue, scope)}
              >
              </ht-switch>
            );
          }
        }
      ],
      searchUserData: {}
    };
  },
  computed: {
  },
  mounted() {
    this.handleSearch();
  },
  methods: {
    handleEdit(row, index) {
      alert(index);
      console.log(row);
    },
    handleDel(row, index) {
      alert(index);
      console.log(row);
    },
    testRefer(newValue, scope) {
      if (newValue === true)
        scope.row.status.c = '100201';
      else
        scope.row.status.c = '100202';

      this.$notify.confirm('是否更改状态?').then(() => {
        alert(scope.row.userName);
      }).catch(() => {
        if (newValue === true)
          scope.row.status.c = '100202';
        else
          scope.row.status.c = '100201';
      });
    },
    async handleSearch(event) {
      try {
        // 拼接查询条件
        this.searchUserData = await this.$crud.search(this.$refs['userSearchFm'], this.$refs['userTableList'], findUsers);
      } catch (e) {
        this.$notify.message(e, 'error');
      }
    }
  }
};
</script>
